import requests
# 需要请求的目标地址
url = 'http://www.rrys2019.com/user/user'


# 登陆请求的网址:
url2 = 'http://www.rrys2019.com/User/Login/ajaxLogin'

# 请求头
headers = {
    'User-Agent':'Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:77.0) Gecko/20100101 Firefox/77.0'
}
# 1.先定义session
req = requests.session()
# 登陆请求时的数据
data ={
'account': '2245935597@qq.com',
'password': '123Woshidjy',
'remember': '1',
'url_back': 'http://www.rrys2019.com/'
}
# 2.发起登陆请求
res = req.post(url=url2,headers=headers,data=data)

# 判断状态
code = res.status_code
print(code)

if code == 200:
    # 发起新的请求，获取目标数据
    res = req.get(url=url,headers=headers)
    code = res.status_code
    if code == 200:
        with open('rr.html','w',encoding='utf-8') as book:
            book.write(res.content.decode('utf-8'))